package com.lap.auth.adapter.driven.web.menu;

import com.lap.auth.application.menu.MenuApiAppService;
import com.lap.auth.application.menu.command.BindMenuApiCmd;
import com.lap.watchdog.starter.annotation.RepeatSubmit;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "菜单绑定api资源", description = "提供菜单绑定api，菜单已绑定api查看")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/v1/menus")
public class MenuApiController {

  private final MenuApiAppService menuApiAppService;

  @Operation(summary = "绑定API到菜单")
  @RepeatSubmit
  @PutMapping("{menuId}/apis")
  public void replaceMenuApis(@PathVariable Integer menuId, @RequestBody BindMenuApiCmd cmd) {
    menuApiAppService.replaceMenuApis(menuId, cmd.getApiSet());
  }

  @Operation(summary = "获取菜单已绑定API")
  @GetMapping("{menuId}/apis")
  public List<String> getApisByMenuId(@PathVariable Integer menuId) {
    return menuApiAppService.queryMenuApisByMenuId(menuId);
  }
}
